﻿using Coldairarrow.Business.BackStage.ConsumeChats;
using Coldairarrow.Entity.BackStage.ConsumeChats;
using Coldairarrow.Util;
using Coldairarrow.Util.DTO;
using Coldairarrow.Util.DTO.OnlineChat;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Coldairarrow.Api.Controllers.BackStage.ConsumeChats
{
    [Route("/BackStage/ConsumeChats/[controller]/[action]")]
    public class ChatRoomController : BaseApiController
    {
        #region DI

        public ChatRoomController(IChatRoomBusiness chatRoomBus)
        {
            _chatRoomBus = chatRoomBus;
        }

        IChatRoomBusiness _chatRoomBus { get; }

        #endregion

        #region 获取

        [HttpPost]
        public async Task<PageResult<ChatRoom>> GetDataList(PageInput<ConditionDTO> input)
        {
            return await _chatRoomBus.GetDataListAsync(input);
        }

        [HttpPost]
        public async Task<ChatRoom> GetTheData(IdInputDTO input)
        {
            return await _chatRoomBus.GetTheDataAsync(input.Id);
        }

        /// <summary>
        /// 后台——获取平台下拉
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<SelectDTO>> GetPlatformList()
        {
            return await _chatRoomBus.GetPlatformListAsync();
        }

        /// <summary>
        /// 后台——获取所有历史客服列表
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<List<SelectDTO>> GetCSSeverList(GetCSSeversInput input)
        {
            return await _chatRoomBus.GetCSSeverListAsync(input);
        }


        /// <summary>
        /// 后台——根据平台类型和客服Id获取用户房间列表
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PageResult<TheRoomDTO>> GetTheRoomList(PageInput<GetRoomListInput> input)
        {
            return await _chatRoomBus.GetTheRoomListAsync(input);
        }

        /// <summary>
        /// 后台——获取聊天记录
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PageResult<ChatLogDTO>> GetTheChatLogList(PageInput<GetCSChatLogsInput> input)
        {
            return await _chatRoomBus.GetTheChatLogListAsync(input);
        }


        #endregion

        #region 提交

        [HttpPost]
        public async Task SaveData(ChatRoom data)
        {
            if (data.Id.IsNullOrEmpty())
            {
                InitEntity(data);

                await _chatRoomBus.AddDataAsync(data);
            }
            else
            {
                await _chatRoomBus.UpdateDataAsync(data);
            }
        }

        [HttpPost]
        public async Task DeleteData(List<string> ids)
        {
            await _chatRoomBus.DeleteDataAsync(ids);
        }

        /// <summary>
        /// 总平台——获取统计数据
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public ChatBigScreenData GetBigScreenData(GetBSInput input)
        {
            return _chatRoomBus.GetBigScreenData(input);
        }

        #endregion
    }
}